package com.mz.ozy.activity.assets;

import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jaeger.library.StatusBarUtil;
import com.mz.ozy.R;
import com.mz.ozy.base.BaseActivity;
import com.mz.ozy.bean.RechargeRecordBean;
import com.mz.ozy.mvp.presenter.RechargeRecordPresenter;
import com.mz.ozy.mvp.view.RechargeRecordContract;
import com.mz.ozy.utils.ToastUtils;
import com.mz.ozy.utils.Utils;
import com.uuzuche.lib_zxing.activity.CodeUtils;

import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * \
 * 充值
 */
public class RechargeActivity extends BaseActivity<RechargeRecordContract.View, RechargeRecordPresenter> implements RechargeRecordContract.View {

    @BindView(R.id.iv_qrcode)
    ImageView ivQrcode;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    ClipboardManager cm;
    @BindView(R.id.bt_copy)
    Button btCopy;
    @BindView(R.id.tv_address_type)
    TextView tvAddressType;
    @BindView(R.id.tv_explain)
    TextView tvExplain;
    @BindView(R.id.ll_recharge_baa)
    LinearLayout mLlRechargeBaa;
    @BindView(R.id.ll_recharge_eth)
    LinearLayout mLlRechargeEth;
    @BindView(R.id.tv_recharge_baa)
    TextView mTvRechargeBaa;
    @BindView(R.id.tv_recharge_eth)
    TextView mTvRechargeEth;
    @BindView(R.id.back)
    ImageView back;


    private String address;

    private boolean isPopDown = false;
    private int type;
    private boolean screen = false;

    public static void go(Context context, int type, boolean screen, String address) {
        Intent intent = new Intent(context, RechargeActivity.class);

        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recharge);
        ButterKnife.bind(this);
        StatusBarUtil.setTranslucentForImageViewInFragment(RechargeActivity.this, 20, null);
      //  mPresenter.getRecharg(this);
        initData();
        initView();
        back.setImageResource(R.mipmap.white_back);
    }

    private void initView() {
        cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);

    }

    private void initData() {
        address = getIntent().getStringExtra("address");
        type = getIntent().getIntExtra("type", 0);
        screen = getIntent().getBooleanExtra("screen", false);
    }

    public void setQrCode(String walletAdress) {
        tvAddress.setText(walletAdress);
        if (!TextUtils.isEmpty(walletAdress)) {
            Bitmap mBitmap = CodeUtils.createImage(walletAdress,
                    Utils.dp2px(this, 240), Utils.dp2px(this, 240),
                    null);
            ivQrcode.setImageBitmap(mBitmap);
            btCopy.setVisibility(View.VISIBLE);
            ivQrcode.setVisibility(View.VISIBLE);
        } else {
            ivQrcode.setVisibility(View.GONE);
            btCopy.setVisibility(View.GONE);
            ToastUtils.showToast(getString(R.string.str_wkp_not_open));
        }
    }


    @OnClick({R.id.back, R.id.right, R.id.bt_copy})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.right:
                startActivity(new Intent(this, RechargeRecordActivity.class));
                break;
            case R.id.bt_copy:
                cm.setText(tvAddress.getText().toString());
                ToastUtils.showToast(getString(R.string.str_copy_success));
                break;
        }
    }

    @Override
    public void getRechargeRecordSuccess(RechargeRecordBean bean) {

    }

    @Override
    public void getRechargeSuccess(JSONObject bean) {
        //setQrCode(bean.getWalletAdress());
    }
}
